using Microsoft.AspNetCore.Mvc;
using Keep.Model;
using Keep.Service;
using Serilog;
using Keep.Const;

namespace Keep.Controllers;

[ApiController]
[Route("api/[controller]/[action]")]
public class UserController : ControllerBase
{
    private readonly IUserService _userService;

    public UserController(IUserService userService)
    {
        _userService = userService;
    }
    [HttpPost(Name = "Login")]
    public async Task<ActionResult<ResultData>> Login([FromBody] User ug)
    {
        Log.Warning("IN");
        User ls = await _userService.Login(ug.Name, ug.PassWord);
        Log.Warning("OUT " + ls);
        return Ok(new ResultData(Static.Enable, ls));
    }

    [HttpGet(Name = "GetAllUser")]
    public async Task<ActionResult<ResultData>> GetAllUser()
    {
        Log.Warning("IN");
        List<User> ls = await _userService.GetAllUser();
        Log.Warning("OUT " + ls.Count);
        return Ok(new ResultData(Static.Enable, ls));
    }

    [HttpGet(Name = "logout")]
    public async Task<ActionResult<ResultData>> Logout()
    {
        Log.Warning("IN");
        bool b = await _userService.LogOut();
        Log.Warning("OUT " + b);
        return Ok(new ResultData(Static.Enable, b));
    }


}